package com.hc.pokemen

import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.RequiresApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.core.view.WindowCompat
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.hc.pokemen.feature_pokemen.presentation.pokemon_detail.PokemonDetailScreen
import com.hc.pokemen.feature_pokemen.presentation.pokemon_list.PokemonListScreen
import com.hc.pokemen.feature_pokemen.presentation.util.Screen
import com.hc.pokemen.ui.theme.PokemenTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    @RequiresApi(Build.VERSION_CODES.R)
    override fun onCreate(savedInstanceState: Bundle?) {
        WindowCompat.setDecorFitsSystemWindows(window, false) // 状态栏隐藏（可占用）
        super.onCreate(savedInstanceState)
        setContent {
            PokemenTheme {
                val systemUiController = rememberSystemUiController()
                val darkIcons = !isSystemInDarkTheme()
                SideEffect {
                    systemUiController.setStatusBarColor(Color.Transparent, darkIcons = darkIcons)
                }
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    val controller = rememberNavController()
                    NavHost(
                        navController = controller,
                        startDestination = Screen.PokemonList.route
                    ) {
                        composable(Screen.PokemonList.route) {
                            PokemonListScreen(controller = controller)
                        }
                        composable(Screen.PokemonDetail.route, Screen.PokemonDetail.arguments) {
                            val dominantColor = remember {
                                val color = it.arguments?.getInt("dominantColor")
                                color?.let { Color(it) } ?: Color.White
                            }
                            val pokemonName = remember {
                                it.arguments?.getString("pokemonName")
                            }
                            PokemonDetailScreen(
                                controller = controller,
                                dominantColor = dominantColor,
                                pokemonName = pokemonName?.lowercase() ?: ""
                            )
                        }
                    }

                }
            }
        }
    }
}
